<html>
<head><meta charset="utf-8"><title>Provide an array-builder/-vec in `core::array`? · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html">Provide an array-builder/-vec in `core::array`?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206505560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/206505560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#206505560">(Aug 10 2020 at 19:53)</a>:</h4>
<p>Between <code>core::array::IntoIter</code> and what's proposed in <a href="https://github.com/rust-lang/rust/pull/75212">https://github.com/rust-lang/rust/pull/75212</a>, the library is looking like it will have most of an implementation of <code>arrayvec</code>.</p>
<p>Would libs be interested in just exposing that somehow?</p>



<a name="240287668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240287668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240287668">(May 26 2021 at 07:26)</a>:</h4>
<p>In the last few days, I've gone from implementing my own invalid array builder (ignoring drops), to finding the <code>array-init</code> crate, then needing more functionality and rolling my own <code>ArrayVec</code> before <span class="user-mention" data-user-id="125270">@scottmcm</span> introduced me to the <code>arrayvec</code> crate. It does see like a very useful struct and, like scottmcm noticed, it seems to already be partially implemented in the form of ArrayGuards throughout some of the std array implementations. I do think it would be good to just absorb the <code>arrayvec::ArrayVec</code> type into core to<br>
a) make std implementations of array features more safe/consistent<br>
b) make it more accessible/well known.</p>



<a name="240296432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240296432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240296432">(May 26 2021 at 09:09)</a>:</h4>
<p>If we do it, It's worth noting there's a way to define an ArrayVec with a lot less code bloat in practice, and allowing methods to take references to array vec (with or) without requiring compile time size requirements. I think it should at least be considered</p>
<p>none of the existing crates do this, and I've considered publishing one that does, but no time. the basic idea is sketched out here <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=da40dafedb02ed7c7723eff5f16d949e">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=da40dafedb02ed7c7723eff5f16d949e</a></p>
<ul>
<li>you have ArrayVec&lt;Arr: ?Sized&gt;</li>
<li>you use this either as ArrayVec&lt;[T; N]&gt; or ArrayVec&lt;[T]&gt;</li>
<li>vec methods go on ArrayVec&lt;[T]&gt;.</li>
<li>ArrayVec&lt;[T; N]&gt; deref{,mut}s to ArrayVec&lt;[T]&gt;</li>
<li>ArrayVec&lt;[T]&gt; deref{,mut}s to [T]</li>
</ul>
<p>in practice this seemed to help compile times a lot in my experience.</p>



<a name="240296796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240296796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240296796">(May 26 2021 at 09:13)</a>:</h4>
<p>Yeah that seems like a decent idea. I'll try draft up an impl in a PR later today using that design</p>



<a name="240296995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240296995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240296995">(May 26 2021 at 09:15)</a>:</h4>
<p>I dont think the implementation PR is the blocker here, it's the decision on whether or not to do it</p>



<a name="240297038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240297038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240297038">(May 26 2021 at 09:16)</a>:</h4>
<p>Indeed. Hopefully someone from the libs team can provide some useful input</p>



<a name="240297091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240297091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240297091">(May 26 2021 at 09:16)</a>:</h4>
<p>there's also a good amount of uncertainty even with this, e.g. how should fallible push() behave</p>



<a name="240297117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240297117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240297117">(May 26 2021 at 09:16)</a>:</h4>
<p>and fallible extend?</p>



<a name="240298661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240298661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240298661">(May 26 2021 at 09:33)</a>:</h4>
<blockquote>
<p>in practice this seemed to help compile times a lot in my experience.</p>
</blockquote>
<p>Is the assembly of the same quality though, i.e. does it know the const size?</p>



<a name="240318941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240318941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240318941">(May 26 2021 at 12:52)</a>:</h4>
<p>my feeling is that this is probably a big enough addition that an RFC would be appropriate.</p>



<a name="240319093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240319093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240319093">(May 26 2021 at 12:53)</a>:</h4>
<p>but i would start with a pre-RFC. and in particular, the thing i am most interested in is the motivation for adding it to std. my sense is that it might not be ubiquitous enough to be worth it. and it sounds like there is some design space that is yet unexplored in the crate ecosystem.</p>



<a name="240320273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240320273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240320273">(May 26 2021 at 13:02)</a>:</h4>
<p>Mostly because I'm seeing people making PRs into the std that are now building upon const generics more, building arrays bit by bit, but it's easy to make mistakes with uninitialised data. On a few examples, I consistently see people making a PR, messing up the Drop unsafety and then attempting to write their own wrapper to handle the drops safely. (exactly what I did but in itertools too). I don't mind dependencies and using crates, but if you don't know what to look for it can be hard to find. If <code>MaybeUninit</code> could suggest you use <code>array::Builder</code> instead, it would save a lot of time/effort and make code a lot safer</p>



<a name="240320423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240320423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240320423">(May 26 2021 at 13:03)</a>:</h4>
<p><code>ArrayVec</code> with a more <code>Vec</code> like API could stay as a crate, but better initialisation makes sense in std to me</p>



<a name="240321157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240321157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240321157">(May 26 2021 at 13:08)</a>:</h4>
<p>oh, i think there is definitely an appetite for easier array initialization, e.g., <a href="https://github.com/rust-lang/rust/pull/75644">https://github.com/rust-lang/rust/pull/75644</a> and <a href="https://github.com/rust-lang/rust/issues/81615">https://github.com/rust-lang/rust/issues/81615</a></p>



<a name="240321479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240321479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240321479">(May 26 2021 at 13:11)</a>:</h4>
<p>Indeed. They're focused on iterators, I think first it makes sense to have a more lower level builder using <code>push(v)</code> and <code>build()</code> which the iterator implementations could build on top of</p>



<a name="240334208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240334208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Giacomo Stevanato <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240334208">(May 26 2021 at 14:35)</a>:</h4>
<p>Note that there's already an internal <code>collect_into_array[_unchecked]</code> <a href="https://github.com/rust-lang/rust/blob/1969c2e312303faa458cf19dad9783165e3c72c8/library/core/src/array/mod.rs#L556-L611">https://github.com/rust-lang/rust/blob/1969c2e312303faa458cf19dad9783165e3c72c8/library/core/src/array/mod.rs#L556-L611</a></p>



<a name="240344520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240344520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240344520">(May 26 2021 at 15:36)</a>:</h4>
<p>Should i draft together an RFC with a basic api then?</p>



<a name="240346807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240346807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240346807">(May 26 2021 at 15:52)</a>:</h4>
<p><span class="user-mention" data-user-id="396593">@Conrad Ludgate</span> <span class="user-mention" data-user-id="209168">@Thom Chiovoloni</span>  I believe there's already an RFC in-progress for ArrayVec: <a href="https://github.com/rust-lang/rfcs/pull/2990">https://github.com/rust-lang/rfcs/pull/2990</a></p>



<a name="240346892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240346892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240346892">(May 26 2021 at 15:53)</a>:</h4>
<p>You are very right! I'll give it a read and leave my thoughts</p>



<a name="240347724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240347724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240347724">(May 26 2021 at 15:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="222471">BurntSushi</span> <a href="#narrow/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F/near/240319093">said</a>:</p>
<blockquote>
<p>the thing i am most interested in is the motivation for adding it to std.</p>
</blockquote>
<p>My personal motivation for supporting an ArrayVec in std is because it fills a conspicuous hole in Rust's array-handling story. This is mostly keenly felt in <a href="https://github.com/rust-lang/rust/issues/81615">https://github.com/rust-lang/rust/issues/81615</a> , where arrays have static size but iterators have dynamic size, and there's no great way to bridge that gap. I believe an ArrayVec would be the perfect bridge between iterators and arrays, and would allow us to at last resolve the design-space chaos of <a href="https://github.com/rust-lang/rust/issues/81615">#81615</a> with <code>impl FromIterator&lt;T&gt; for ArrayVec&lt;T&gt;</code>.</p>



<a name="240348865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240348865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240348865">(May 26 2021 at 16:06)</a>:</h4>
<p>I had a very similar desire for itertools. I wanted to implement a <code>next_array</code> method that would take <code>N</code> elements from the iterator, but not consume the entire iterator. So even if FromIterator gets implemented, I still would need to either re-write the implementation or use an external crate</p>



<a name="240350131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240350131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240350131">(May 26 2021 at 16:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="256342">bstrie</span> <a href="#narrow/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F/near/240346807">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="396593">Conrad Ludgate</span> <span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span>  I believe there's already an RFC in-progress for ArrayVec: <a href="https://github.com/rust-lang/rfcs/pull/2990">https://github.com/rust-lang/rfcs/pull/2990</a></p>
</blockquote>
<p>The only thing about this RFC is it's more focused on the vec side of the ArrayVec, and less about the Array part. It doesn't seem fit in the way they've described to actually build a std array. And like <span class="user-mention" data-user-id="222471">@BurntSushi</span> mentions, the crate space seems better fit for the vec side of the structure. I'll create a new RFC but reference this one as prior art</p>



<a name="240357991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240357991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240357991">(May 26 2021 at 17:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="222471">BurntSushi</span> <a href="#narrow/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F/near/240319093">said</a>:</p>
<blockquote>
<p>the thing i am most interested in is the motivation for adding it to std.</p>
</blockquote>
<p>I suppose the things I'm thinking of most might not strictly need the whole thing.  The major point I see is that people keep reimplementing the "push things onto an array with correct drop handling", and that's the kind of thing that's an obvious need with const generics.</p>
<p>But by the time we have all the code for that, as well as the related code in <code>array::IntoIter</code>, we've done most of <code>ArrayVec</code>.  It feels like if we do try to just make an "array builder" type it'd probably end up getting PRs for <code>Vec</code>-like things anyway.</p>



<a name="240358293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240358293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240358293">(May 26 2021 at 17:11)</a>:</h4>
<p>I suppose a potentially-easier direction would be to provide an array-builder <em>method</em>.  That doesn't necessarily fit everything perfectly, but hacks like <code>[(); N].map(|()| f())</code> could work to be a temporary way to to this without needing to resolve a ton of API concerns.</p>



<a name="240358354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240358354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240358354">(May 26 2021 at 17:11)</a>:</h4>
<p>I guess my strongest feeling is just that <em>something</em> for this should get stabilized sooner rather than later.</p>



<a name="240358355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240358355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240358355">(May 26 2021 at 17:11)</a>:</h4>
<p><span class="user-mention silent" data-user-id="330154">The 8472</span> <a href="#narrow/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F/near/240298661">said</a>:</p>
<blockquote>
<blockquote>
<p>in practice this seemed to help compile times a lot in my experience.</p>
</blockquote>
<p>Is the assembly of the same quality though, i.e. does it know the const size?</p>
</blockquote>
<p>Yes, basically. Essentially LLVM isn't forced to duplicate all these functions, but it can trivially do so if it decides its a good bet.</p>



<a name="240359079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240359079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240359079">(May 26 2021 at 17:17)</a>:</h4>
<p>Not sure if I'll get it done tonight, but here's a start to the new RFC <a href="https://github.com/conradludgate/rfcs/blob/array-builder/text/0000-array-builder.md">https://github.com/conradludgate/rfcs/blob/array-builder/text/0000-array-builder.md</a></p>



<a name="240373805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240373805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Giacomo Stevanato <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240373805">(May 26 2021 at 19:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="256342">bstrie</span> <a href="#narrow/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F/near/240347724">said</a>:</p>
<div class="codehilite"><pre><span></span><code>`impl FromIterator&lt;T&gt; for ArrayVec&lt;T&gt;`.
</code></pre></div>
<p>That still has the problem of whether to error or not if the iterator has too many items</p>



<a name="240374871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240374871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240374871">(May 26 2021 at 19:06)</a>:</h4>
<p>the idea is that conversion from an iterator to an ArrayVec is infallible, and the type provides methods for dealing with the dynamic nature of iterators in what ever manner is most fitting for your use</p>



<a name="240375485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240375485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240375485">(May 26 2021 at 19:10)</a>:</h4>
<p>Yeah, that's exactly why I'm making this separated from iterators for now. It's a conversation for another topic. This at least gets an implementation that can work with all different designs of FromIterator</p>



<a name="240386853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Provide%20an%20array-builder/-vec%20in%20%60core%3A%3Aarray%60%3F/near/240386853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Conrad Ludgate <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Provide.20an.20array-builder.2F-vec.20in.20.60core.3A.3Aarray.60.3F.html#240386853">(May 26 2021 at 20:31)</a>:</h4>
<p><a href="https://github.com/rust-lang/rfcs/pull/3131">https://github.com/rust-lang/rfcs/pull/3131</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>